package util;

/**
 * 2D Point with integer coordinates
 */
public class Point {
	
	/**
	 * State variables
	 */
	private int _x = 0;
    private int _y = 0;
    
    /* Initialize point */
    public Point(int x, int y) {
    	_x = x; 
    	_y = y;
    }
    
    /* Format to string */
    public String toString(){
        return "("+_x+", "+_y+")";
    }
  
    /* Access coordinates */
    public int getX() { 
    	return _x; 
    }
    
    public int getY() { 
    	return _y;
    }

    /* Set coordinates */
    public void setX(int x) {    
    	_x = x;
    }

    public void setY(int y) {    
        _y = y;
    }
    
    /* Copy another point coordinates */
    public void copy(Point pt) {
    	_x = pt.getX();
    	_y = pt.getY();
    }
  
    /* Shift by given delta coordinates */
    public void shift(int dx, int dy) {
    	_x += dx;
    	_y += dy;
  	}
    
    /* Calculate sum of two points */
    public Point add(Point pt) {
    	return new Point(_x + pt.getX(), _y + pt.getY());
  	}
    
    /* Calculate difference between two points */
    public Point diff(Point pt) {
    	return new Point(_x - pt.getX(), _y - pt.getY());
    }
}
